﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Mediator
{
    public partial class LoginFrame : Form, IMediator
    {
        public LoginFrame()
        {
            InitializeComponent();

            CreateColleagues();
            ColleagueChanged();
        }


        #region IMediator メンバ

        public void CreateColleagues()
        {
            chkGuest.SetMediator(this);
            chkLogin.SetMediator(this);
            txtUser.SetMediator(this);
            txtPass.SetMediator(this);
            btnOK.SetMediator(this);
            btnCancel.SetMediator(this);
        }

        public void ColleagueChanged()
        {
            if (chkGuest.Checked)
            {
                txtUser.SetColleagueEnabled(false);
                txtPass.SetColleagueEnabled(false);
                btnOK.SetColleagueEnabled(true);
            }
            else
            {
                txtUser.SetColleagueEnabled(true);
                UserPassChanged();
            }
        }

        #endregion


        private void UserPassChanged()
        {
            if (txtUser.Text.Length > 0)
            {
                txtPass.SetColleagueEnabled(true);

                if (txtPass.Text.Length > 0)
                {
                    btnOK.SetColleagueEnabled(true);
                }
                else
                {
                    btnOK.SetColleagueEnabled(false);
                }
            }
            else
            {
                txtPass.SetColleagueEnabled(false);
                btnOK.SetColleagueEnabled(false);
            }
        }
    }
}
